/*
 *	This file is part of Lounge-Cast.
 *
 *  Author:  	Markus Moormann
 *	E-mail:  	mmoorman@uni-osnabrueck.de
 *	Copyright:	University of Osnabrueck (Zentrum Virtuos)
 * 	Website:	www.uni-osnabrueck.de
 *	Date:		16.02.2011
 *
 *	Lounge-Cast is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *	Lounge-Cast is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Lounge-Cast.  If not, see <http://www.gnu.org/licenses/>.
 */
package multimedia.model.vo
{
	import mx.collections.ArrayCollection;

	/**
	 * class representing a playlist
	 */
	[Bindable]
	[RemoteClass(alias="backend.vo.PlaylistVO")]
	public class PlaylistVO
	{
		/**
		 * internal id of the playlist
		 */
		public var playlist_id:uint;
		/**
		 * the media belonging to this playlist
		 */
		public var media:ArrayCollection;
		/**
		 * inheritance level indicating on which step 
		 * this playlist stands
		 */
		public var inheritance_level:uint;
		/**
		 * playlist this playlists inherits its media from
		 */
		public var inheritance_from:PlaylistVO;
		/**
		 * description of the playlist
		 */
		public var description:String;

		/**
		 * default constructor setting some standard data
		 */
		public function PlaylistVO()
		{
			this.playlist_id = 0;
			this.media = new ArrayCollection();
			this.inheritance_level = 1;
			this.description = "neue Playlist";
		}

		/**
		 * method to check whether this playlist already is inheritating from given playlist
		 * to prevent a circle of inheritation
		 * 
		 * @param playlist the playlist to check the inheritation for
		 * 
		 * @return true if this playlists already inherits from the given playlist, false else
		 */
		public function inheritsFrom(playlist:PlaylistVO):Boolean
		{
			if (this.playlist_id == playlist.playlist_id)
			{
				return true;
			}
			if (this.inheritance_from != null)
			{
				return this.inheritance_from.inheritsFrom(playlist);
			}
			else
			{
				return false
			}
		}
		
		/**
		 * checks whether a media is already in the playlist
		 * 
		 * @param media the media to check
		 * 
		 * @return true of the media is already in the playlist, false else
		 */
		public function containsMedia(media:MediaVO):Boolean
		{
			for each(var media2:MediaVO in this.media)
			{
				if(media == media2)
				{
					return true;
				}
			}
			return false;
		}

	}
}